package day2;

import java.util.Objects;

/**
 * @author oldliu
 * @since 1.0
 */
public class People implements Comparable<People> {
    private String name;
    private final String sex;
    private int age;

    public People() {
        sex = "男";
    }

    public People(String name, String sex, int age) {
        this.name = name;
        this.sex = sex;
        this.age = age;
    }

    public People(String name, String sex) {
        this.name = name;
        this.sex = sex;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }


    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "人{" +
                "姓名='" + name + '\'' +
                ", 性别='" + sex + '\'' +
                ", 年龄=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        People people = (People) o;
        return Objects.equals(name, people.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }

    @Override
    public int compareTo(People o) {
        //return this.name.compareTo(o.name);
        return this.age - o.age;
        //  return o.age-this.age;
    }
//    @Override
//    public int hashCode() {
//        if(this.name==null)
//            return 0;
//        return name.hashCode();
//    }
//
//    @Override
//    public boolean equals(Object obj) {
//        if (obj instanceof People) {
//            People p = (People) obj;
//            if (this.name == null && p.name == null)
//                return true;
//            if (this.name != null)
//                return this.name.equals(p.name);
//        }
//        return false;
//    }
}
